<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>蒯兴鹏会员注册页面</title>
    <%--静态包含头部信息--%>
    <%@include file="/pages/common/header.jsp" %>
    <link rel="shortcut icon" href="../../static/img/logo_chzu1.png" type="image/x-icon" />
    <script type="text/javascript">
        // 页面加载完成之后
        $(function () {
            //查看用户名是否可用
            $("#code_img").click(function (){
                this.src="${pageContext.request.contextPath}/kaptcha.jpg?d=" + new Date();//this.src = this.src;
            });

            $("#sub_btn").click(function () {
                //验证用户名 5-12字母下划线数字组成;
                var userText = $(`#name`).val();
                var userPatt = /^\w{5,12}$/;
                if (!userPatt.test(userText)) {
                    $("span.errorMsg").text("用户名不合法！");
                    return false;
                }

                //验证性别
                if(!$("#nan").attr("checked") && !$("#nv").attr("checked")){
                    $("span.errorMsg").text("请选择性别！");
                    return false;
                }

                //验证密码 5-12字母下划线数字组成;
                var passText = $("#password").val();
                var passPatt = /^\w{5,12}$/;
                if (!passPatt.test(passText)) {
                    $("span.errorMsg").text("密码不合法！");
                    return false;
                }
                //验证确认密码, 和密码相同;
                var passtext = $("#repwd").val();
                if (passtext != passText) {
                    $("span.errorMsg").text("两次密码不相同！");
                    return false;
                }
                //邮箱验证
                var emailText = $("#email").val();
                var emailPatt = /^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/;
                if (!emailPatt.test(emailText)) {
                    $("span.errorMsg").text("邮箱不合法！");
                    return false;
                }
                //验证码验证
                var codeText = $("#code").val();
                codeText = codeText.trim();
                if (codeText == null || codeText == "") {
                    $("span.errorMsg").text("验证码不合法！");
                    return false;
                }
                $(".errorMsg").text("");
            });
        });


    </script>
    <style type="text/css">
        .login_form {
            height: 600px;
            margin-top: 25px;
        }
    </style>
</head>
<body>
<div id="login_header">
    <img class="logo_img" alt="" src="static/img/logo.gif">
</div>

<div class="login_banner">

    <div id="l_content">
        <span class="login_word">欢迎注册</span>
    </div>

    <div id="content">
        <div class="login_form">
            <div class="login_box">
                <div class="tit">
                    <h1>注册蒯兴鹏会员</h1>
                    <span class="errorMsg">
<%--                        <%=request.getAttribute("msg") == null ? "请输入注册信息" : request.getAttribute("msg")%>--%>
                        ${empty requestScope.msg ? "请输入注册信息" : requestScope.msg}
                    </span>
                </div>
                <div class="form">
                    <form action="${pageContext.request.contextPath}/user/registUser" method="post">
                        <label>用户名称：</label>
                        <input class="itxt" type="text" placeholder="请输入用户名"
                               autocomplete="off" tabindex="1" name="name" id="name"
                        value="${requestScope.username}"/>
                        <br/>
                        <br/>
                        <label>用户性别：</label>
                        <input type="radio" value="男" name="sex" id="nan"/>男
                        <input type="radio" value="女" name="sex" id="nv"/>女
                        <br/>
                        <br/>
                        <label>用户密码：</label>
                        <input class="itxt" type="password" placeholder="请输入密码"
                               autocomplete="off" tabindex="1" name="password" id="password"/>
                        <br/>
                        <br/>
                        <label>确认密码：</label>
                        <input class="itxt" type="password" placeholder="确认密码"
                               autocomplete="off" tabindex="1" name="repwd" id="repwd"/>
                        <br/>
                        <br/>
                        <label>电子邮件：</label>
                        <input class="itxt" type="text" placeholder="请输入邮箱地址"
                               autocomplete="off" tabindex="1" name="email" id="email"
                        value="<%=request.getAttribute("email") == null ? "" : request.getAttribute("email")%>"/>
                        <br/>
                        <br/>
                        <label>验证码：</label>
                        <input class="itxt" type="text" name="code" style="width: 80px;" id="code"/>
                        <img alt="" src="kaptcha.jpg" style="float: right; margin-right: 40px; width: 100px; height: 28px;" id="code_img">
                        <br/>
                        <br/>
                        <input type="submit" value="注册" id="sub_btn"/>
                    </form>
                </div>

            </div>
        </div>
    </div>
</div>
<%--静态包含页脚信息--%>
<%@include file="/pages/common/footer.jsp" %>
</body>
</html>
